package ch.ffhs.esma.bunk_weiss.notepad;

/**
 * @author: Tobias Weiss / Julian Bunk
 * @Date: 04.01.2015
 */

import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;

public class DatabaseAdapter {

	SQLiteDatabase database;
	DataBaseHandler dbHelper;

	public DatabaseAdapter(Context context) {
		dbHelper = new DataBaseHandler(context);
	}

	public void open() {
		database = dbHelper.getWritableDatabase();
	}

	public void close() {
		database.close();
	}

	public long insertNotiz(String titel, String text, String datum,
			String zeit, String bildpfad, String soundpfad) {
		ContentValues cv = new ContentValues();
		cv.put("title", titel);
		cv.put("notiztext", text);
		cv.put("date", datum);
		cv.put("time", zeit);
		cv.put("bildpfad", bildpfad);
		cv.put("soundpfad", soundpfad);
		return database.insert("notizen", null, cv);
	}

	// Hole alle Notizen via Cursor und frage Datenbank ab (Query)
	public Cursor fetchAllNotizen() {
		Cursor mCursor = database
				.query("notizen", new String[] { "_id", "title", "notiztext",
						"date", "time", "bildpfad", "soundpfad" }, null, null,
						null, null, null);

		if (mCursor != null) {
			mCursor.moveToFirst();
		}
		return mCursor;
	}
}
